﻿using rbac.domain.Entity;
using rbac.domain.Interface;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace rbac.domain.Impl
{
    public class UserRoleRepository:IUserRoleRepository
    {
        private readonly RbacContext _context;

        public UserRoleRepository(RbacContext context)
        {
            _context = context;
        }

        public IQueryable<UserRole> UserRoles()
        {
            return _context.UserRoles;
        }

        public IQueryable<Role> UserRolesBuUserId(params int[] userid)
        {
            //var roleidlist = _context.UserRoles.Where(x => x.UserId == userId)
            //    .Select(x => x.RoleId);
            //return _context.Roles.Where(x => roleidlist.Contains(x.Id));
            return from a in _context.UserRoles
                   join b in _context.Roles
                   on a.RoleId equals b.Id 
                   where userid.Contains(a.UserId)
                   select b;
        }
    }
}
